/* SGATOR
 * elem.h
 */

#ifndef SGELEM_H
#define SGELEM_H

#include "base.h"
#include "types.h"
#include "boundvar.h"
#include "plugin.h"

struct _SgOutNode {
  SgElem *elem; /* element that contain this output node*/
  SgUShort nb; /* output node number of the element */
  SgUInt pnb; /* port number */
  SgBool iscontrol;
  SgList *buffref;
  SgStack *inpnodes;
  SgInpNode *left;
};

struct _SgInpNode {
  SgElem *elem;
  SgUShort nb;
  SgUInt pnb;
  SgBool iscontrol;
  SgOutNode *outnode;
  SgOutNode *right;
};

struct _SgElem {
  SgPluginDescP desc;
  SgInt _type;
  SgMod *_mod;
  SgUInt _id;
  SgBool _st;
  SgBool _rst; /* 'has run' status */
  SgBool _hoc; /* has control outputs ? */
  SgULong _sample;
  SgBool _needownbuffs;
  SgInpNode **_inps;
  SgOutNode **_outs;
  SgUShort inps_nb, outs_nb, vars_nb;
  SgFloat **ibuffs, **obuffs;
  SgULong *istartsample;
  SgBool *ineedrun;
  SgVal *vars;
  SgBoundVar *bvars;
  SgSingle samplerate;
  void **data;
  void* _on_run; /* shortcut */
  SgVal *_xtra_params;
};

#define sg_elem_get_buffsize(e) (e->_mod->buffsize)

SgElem *sg_make_elem(SgMod *mod, SgPluginDescP desc, SgInt type);
void sg_init_elem(SgElem *elem);
SgElem *sg_make_init_elem(SgMod *mod, SgPluginDescP desc, SgInt type);
void sg_reset_elem(SgElem *elem);
void sg_remove_elem(SgElem *elem);
void sg_connect_elems(SgElem *elem0, SgElem *elem1, SgUShort o, SgUShort i);
void sg_unconnect_elems(SgElem *elem, SgUShort i);
void sg_set_buffs(SgElem *elem);
void sg_reset_buffs(SgElem *elem);
void sg_connect_elems_rt(SgElem *elem0, SgElem *elem1, SgUShort o, SgUShort i);
void sg_unconnect_elems_rt(SgElem *elem, SgUShort i);

#endif

/* end */

